package cn.jiahua.test13;

import java.util.concurrent.BrokenBarrierException;
import java.util.concurrent.CyclicBarrier;

public class Test2 {


    /**
     * 在酒楼等待人齐，再一起吃饭
     * 6个人
     * @param args
     */
    public static void main(String[] args) {


        //栅栏
        CyclicBarrier cyclicBarrier=new CyclicBarrier(6,()->{
            System.out.println("人齐了，吃饭了！");
        });
            for (int i=1;i<=6;i++){

                new Thread(()->{
                    System.out.println(Thread.currentThread().getName()+"已经到酒店了！等待吃饭");
                    //等待.
                    try {
                        cyclicBarrier.await();
                    } catch (InterruptedException e) {
                        e.printStackTrace();
                    } catch (BrokenBarrierException e) {
                        e.printStackTrace();
                    }

                }).start();
            }
    }




}
